package com.aht.qywxwebdemo;

import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WxCpConfig {
    /**
     * 企业微信企业id
     */
    @Value("${ldnh.cpwx.corpid}")
    private String corpid;

    /**
     * 企业微信应用id
     */
    @Value("${ldnh.cpwx.agentid}")
    private Integer agentid;

    /**
     * 企业微信应用密钥
     */
    @Value("${ldnh.cpwx.secret}")
    private String secret;

    @Bean
    public WxCpService wxCpService() {
        WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl();
        config.setCorpId(corpid);
        config.setAgentId(agentid);
        config.setCorpSecret(secret);
        config.setAesKey(secret);
        WxCpService wxCpService = new WxCpServiceImpl();
        wxCpService.setWxCpConfigStorage(config);
        return wxCpService;
    }
}
